const path = require('path');
const webpack = require("webpack");
// const ExtractTextPlugin = require("extract-text-webpack-plugin");
// const HtmlWebpackPlugin = require('html-webpack-plugin');
// console.log("path.join(__dirname, '/dist')",__dirname, path.join(__dirname, '/dist'))
module.exports = {
    mode: 'development',
    entry:{
        // entry:['babel-polyfill',  'react-hot-loader/patch'],
        index:path.join(__dirname, '/public/index.js'),
        // manage:path.join(__dirname, '/public/manage.js'),
        // vendor: ['moment', "antd", 'react', 'react-dom', 'reacyt-router', 'classnames'],
    },
    output: {
        // publicPath: "/dist",
        // path: path.join(__dirname, '/dist'),
        path: path.join(__dirname,"/dist"),
        publicPath: path.join(__dirname,"/dist"),
        filename: "[name].bundle.js",
    },
    devServer: {
        inline: true,//实时刷新
        port: 3333,
        historyApiFallback: true
    },
    externals:{
        jquery:"jQuery",
        // JSEncrypt:"JSEncrypt"
        // antd:"antd",
    },
    optimization: {
        minimize: false
    },
    plugins:[
        // new HtmlWebpackPlugin({template:"./index.html"}),
        new webpack.DllReferencePlugin({
            context: __dirname,
            manifest: require('./manifest.json')
        }),
        new webpack.DefinePlugin({
            'process.env.NODE_ENV': JSON.stringify('production')
        }),
        new webpack.optimize.MinChunkSizePlugin({
            minChunkSize: 1000000 // Minimum number of characters
        }),
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery"
        }),
        // new ExtractTextPlugin("styles.css"),
    ],
    // optimization: {
    //     splitChunks: {
    //       chunks: 'initial',
    //       automaticNameDelimiter: '.',
    //       cacheGroups: {
    //         vendors: {
    //           test: /[\\/]node_modules[\\/]/,
    //           priority: 1
    //         }
    //       }
    //     },
    //     // commons: {
    //     //     test: /[\\/]node_modules[\\/]/,
    //     //     name: "vendors",
    //     //     chunks: "all"
    //     // }
    // },
    module: {
        rules: [{
            test: /\.(js|jsx)$/,
            loader: 'babel-loader',
            exclude: /node_modules/,
            options:{
                plugins:['transform-runtime',["import",{ "libraryName": "antd", "style": "true" }]],
                presets:['es2015', 'react', 'stage-2'],
            }
        },{ 
            test: /\.css$/, 
            use:['style-loader', 'css-loader'],
        },
        {
            test: /\.scss$/,
            use: ['style-loader',"css-loader","sass-loader"],
        },
        {
            test: /\.less$/,
            use: ['style-loader', 'css-loader', 'less-loader']
            // use: ExtractTextPlugin.extract({
            //     fallback: 'less-loader',
            //     use: ['style-loader', 'css-loader' ]
            // })
        },
        {
            test: /\.(eot|woff|woff2|ttf|svg)([\\?]?.*)$/,
            // exclude: /node_modules/,
            loader: "file-loader"
        },
        { 
            test: /\.ts$/, use: 'ts-loader' 
        },{ 
            
            test: /\.(jpg|jpeg|png)$/, use:['url-loader']
        }, 
        ]
    }
}